package org.bookie.web.pages.admin;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Iterator;

import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.scriptaculous.ListItemRenderer;
import org.bookie.model.Event;

public class EventListRenderer implements ListItemRenderer {
	/**Pattern describing the date and time format*/
	public static final String PATTERN = "d MMM yyyy";
	
	/**
	 * {@inheritDoc}
	 */
	public void renderList(IMarkupWriter writer, IRequestCycle cycle,
			Iterator values) {
		if (cycle.isRewinding()) return;
		
		writer.begin("ul");
		 while (values.hasNext()) {
			 Event event = (Event)values.next();
			 writer.begin("li");
			 writer.appendAttribute("id", String.valueOf(event.getId()));
			 Format format = new SimpleDateFormat(EventListRenderer.PATTERN);
			 writer.print(format.format(event.getEndDate()));
			 writer.print(": ");
			 writer.print(event.getLabel());
			 writer.end("li");
		 }
		writer.end();
	}

}
